package com.panshi.controller;

import com.panshi.entity.AppAnswer;
import com.panshi.entity.SysAnswerCheck;
import com.panshi.service.AnswerCheckService;
import com.panshi.service.AnswerService;
import com.panshi.tools.DataResult;
import com.panshi.tools.PageBean;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Api(tags = "回答业务接口")
@RestController
@Slf4j
public class AnswerController {

    @Autowired
    private AnswerService answerService;

    @Autowired
    private AnswerCheckService answerCheckService;

    @GetMapping("/matter/byMid/{matterId}")
    //@HystrixCommand(fallbackMethod = "queryAnswerGet")
    public List<AppAnswer> queryAnswerByMid(@PathVariable Integer matterId){
        List<AppAnswer> list = answerService.queryAnswerByMid(matterId);
        return list;
    }

    @GetMapping("/matter/page/{matterId}")
    public DataResult queryAnswerMidPage(@PathVariable Integer matterId, PageBean pageBean){
        return answerService.queryAnswerMidPage(matterId,pageBean);
    }

    @GetMapping("/matter/updatePt/{answerId}/{code}")
    public void updatePariseTread(@PathVariable Integer answerId, @PathVariable String code){
        System.out.println("answer: " + answerId +"   " +code);
        answerService.updatePariseTread(answerId,code);
    }

    // 熔断方法
    public List<AppAnswer> queryAnswerGet(@PathVariable Integer matterId){
        List<AppAnswer> list  = new ArrayList<>();
        new AppAnswer().setMatterId(matterId).setAnswerContent( "matterId" + matterId+", 请求服务超时，或者没有对应的数据~请重试 => AnswerService" );
        return list;
    }




}
